package 剑指offer.zw_04_二维数组中的查找;

class Solution {
    public static void main(String[] args) {
        int[][] matrix = {{1, 3, 5}, {2, 3, 6}};
        int target = 5;
        boolean b = findNumberIn2DArray(matrix, target);
        System.out.println(b);
    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        int i = matrix.length - 1, j = 0;
        while (i >= 0 && j < matrix[0].length) {
            if (matrix[i][j] > target) i--;
            else if (matrix[i][j] < target) j++;
            else return true;
        }
        return false;
    }


//    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
//        if (matrix.length == 0) return false;
//        int m = matrix.length, n = matrix[0].length;
//        for (int i = 0; i < m; i++) {
//            for (int j = 0; j < n; j++) {
//                if (matrix[i][j] == target) return true;
//            }
//        }
//        return false;
//    }
}